<?php
class Admin_SeriesController extends My_Controller_Admin_Choix
{
	public function indexAction()
	{
	    $rowPerPage = $this->_getParam('rowperpage', 20);
		$currentPage = 1;
		$page = $this->_getParam('page', 1);
		if(!empty($page)) {
			$currentPage = $page;
		}

		$archive = $this->_getParam('archive', false);
		$collection = Mage::getModel('admin/series')->getCollection($archive);
		$paginator = Zend_Paginator::factory($collection);
		$paginator->setItemCountPerPage($rowPerPage);
		$paginator->setCurrentPageNumber($currentPage);

		$this->view->page = $page;
		$this->view->paginator = $paginator;
	}

	public function editAction()
	{
	    $id = $this->_getParam('id', 0);
	    $object = Mage::getModel('admin/series');
	    if ($id) {
	        $object->load($id);
	    }
	    $this->view->object = $object;
	}

	public function newAction()
	{
	    $this->_forward('edit');
	}

	public function saveAction()
	{
	    $id = $this->_getParam('id');
	    $model = Mage::getModel('admin/series');
	    if ($id) {
	        $model->load($id);
	    }
	    $data = $this->_getParam('data');
	    if (!isset($data['archive'])) {
	        $data['archive'] = 0;
	    }
	    $model->addData($data)->save();
	    $this->_redirect('admin/series/?num_vente=' . $this->view->numVente);
	    exit;
	}

	public function deleteAction()
	{
	    $id = $this->_getParam('id');
	    Mage::getModel('admin/series')->load($id)->delete();
	    $this->_redirect('admin/series/?num_vente=' . $this->view->numVente);
	    exit;
	}
}

